local powei = fk.CreateSkill {

  name = "joy__powei",

  tags = { Skill.Wake, },

}



powei:addEffect(fk.TurnEnd, {
  name = "joy__powei",
  frequency = Skill.Wake,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(powei.name) and player:usedSkillTimes(powei.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    return not table.find(player.room.alive_players, function(p)
      return p:getMark("@@joy__powei_wei") > 0
    end) 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player, "joy__shenzhuo", nil, true, false)
    local n = player.getMark(player,"joy__poweilose")
    local id = {}
      for _, p in ipairs(room:getAlivePlayers()) do
        if p:getMark("@@joy__powei_wei") > 0 then
          table.insert(id,p)
        end
      end
    if not player.dead then
      room:drawCards(player,n-#id,powei.name)
    end
  end,
})

return powei